[assembly: System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Titles.MinimizeButton.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Titles.MinimizeButton.debug.js", "application/x-javascript")]

namespace BM.Tools.WebControls.MForm.Controls.Titles
{
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using AjaxControlToolkit;

    using BM.Tools.WebControls.MForm.Controls.Helper;
    using BM.Tools.WebControls.MForm.ScriptReferences;

    /// <summary>
    /// A cotrol that displays an image for minimization or maximization
    /// </summary>
    [DesignTimeVisible(false)]
    [ClientScriptResource("BM.Tools.WebControls.MForm", "BM.Tools.WebControls.MForm.Controls.Titles.MinimizeButton.js")]
    public class MinimizeButton : WebControl
    {
        private const string MinimizeButtonCssClass = "MB";

        /// <summary>
        /// Gets or sets a value indicating whether Collapsed.
        /// </summary>
        /// <value>
        /// The collapsed.
        /// </value>
        public bool Collapsed
        {
            get;

            set;
        }

        /// <summary>
        /// Gets ImageSource.
        /// </summary>
        /// <value>
        /// The image source.
        /// </value>
        public string ImageSource
        {
            get
            {
                return ScriptIncluder.MapPath(
                        DesignMode, Page, ImagePath + "btn_minimise_" + CollapsedModifier + "_1.gif");
            }
        }

        /// <summary>
        /// Gets ImagePath.
        /// </summary>
        /// <value>
        /// The image path.
        /// </value>
        internal string ImagePath
        {
            get
            {
                return this.ParentOfType<Offspring>().Root.CommonImagesPath;
            }
        }

        /// <summary>
        /// Gets CollapsedModifier.
        /// </summary>
        /// <value>
        /// The collapsed modifier.
        /// </value>
        protected virtual string CollapsedModifier
        {
            get
            {
                if (Collapsed)
                {
                    return "down";
                }

                return "up";
            }
        }

        /// <summary>
        /// The img tag key
        /// </summary>
        /// <value>
        /// The tag key.
        /// </value>
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Img;
            }
        }

        /// <summary>
        /// adds custom attributes to the image
        /// </summary>
        /// <param name="writer">
        /// A <see cref="T:System.Web.UI.HtmlTextWriter"></see> that represents the output stream to render HTML content on the client. 
        /// </param>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Src, ImageSource);
            writer.AddAttribute(HtmlTextWriterAttribute.Class, MinimizeButtonCssClass);
            writer.AddAttribute("onmouseover", "BM.MinimizeButton.switchImg(this, 2);");
            writer.AddAttribute("onmouseout", "BM.MinimizeButton.switchImg(this, 1);");
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "BM.MinimizeButton.showHideSection(this);");
        }

        /// <summary>
        /// Include resources.
        /// </summary>
        /// <param name="e">
        /// The event args.
        /// </param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            ScriptIncluder.IncludeResources(this);
        }
    }
}